//
//  UIViewController+ZTHUD.m
//  AFNetworking
//
//  Created by 武得亮 on 2021/3/14.
//

#import "UIViewController+ZTHUD.h"
#import <objc/runtime.h>

#import "ZTMacros.h"
#import "ZTTopMoveButton.h"

static const void *HttpRequestHUDKey = &HttpRequestHUDKey;

@interface UIViewController(HUD_Private)

@property (nonatomic, strong) MBProgressHUD *proHud;

@end

@implementation UIViewController (ZTHUD)

const char *kHudKey = "ProgressHUD_Key";

- (void)showHUDOnlyText:(NSString *)labelText afterDelay:(NSTimeInterval)afterDelay
{
    if (labelText != nil && ![labelText isEqualToString:@""]) {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.mode = MBProgressHUDModeText;
        hud.detailsLabel.font = [UIFont systemFontOfSize:13.0];
        if ([labelText isEqualToString:@"未能读取数据，因为格式不正确。"]) {
            labelText = @"无法连接到服务器";
        }
        hud.detailsLabel.text = labelText;
        hud.removeFromSuperViewOnHide = YES;
        [hud hideAnimated:YES afterDelay:afterDelay];
    }
}


- (void)showHUDOnlyText:(NSString *)labelText
{
    if (labelText != nil && ![labelText isEqualToString:@""]) {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.mode = MBProgressHUDModeText;
//        hud.bezelView.color = HEXCOLOR(0x9d9d9d);
        hud.bezelView.color = [UIColor blackColor];
        hud.label.font = [UIFont systemFontOfSize:13.0];
        hud.label.textColor = [UIColor whiteColor];
        if ([labelText isEqualToString:@"未能读取数据，因为格式不正确。"]) {
            labelText = @"无法连接到服务器";
        }
        hud.label.text = labelText;
        hud.removeFromSuperViewOnHide = YES;
        [hud hideAnimated:YES afterDelay:1.0];
    }
}

- (void)showHUDOnly3Text:(NSString *)labelText
{
    if (labelText != nil && ![labelText isEqualToString:@""]) {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.mode = MBProgressHUDModeText;
        //        hud.bezelView.color = HEXCOLOR(0x9d9d9d);
        hud.bezelView.color = [UIColor blackColor];
        hud.label.font = [UIFont systemFontOfSize:13.0];
        hud.label.textColor = [UIColor whiteColor];
        if ([labelText isEqualToString:@"未能读取数据，因为格式不正确。"]) {
            labelText = @"无法连接到服务器";
        }
        hud.label.text = labelText;
        hud.removeFromSuperViewOnHide = YES;
        [hud hideAnimated:YES afterDelay:3.0];
    }
}

/** 带确定和取消按钮的提示框 */
- (void)showAlertViewWithTitle:(NSString *)title subTitle:(NSString *)subTitle confirmBtnTitle:(NSString *)confirmTitle cancelBtnTitle:(NSString *)cancelTitle confirmBlock:(ConfirmClickBlock)confirmBlock cancelBlock:(CancelClickBlock)cancelBlock
{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:subTitle preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        cancelBlock();
    }];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:confirmTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        confirmBlock();
    }];
    [alertVC addAction:cancelAction];
    [alertVC addAction:confirmAction];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:alertVC animated:YES completion:nil];
    });
}

/** 带取消按钮的Sheet弹框 */
- (void)showActionSheetWithSubTitle:(NSString *)subTitle cancelTitle:(NSString *)cancelTitle confirmBlock:(ConfirmClickBlock)confirmBlock cancelBlock:(CancelClickBlock)cancelBlock{
    UIAlertController * alertView = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
     UIAlertAction *fAction =  [UIAlertAction actionWithTitle:subTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
         confirmBlock();
    }];
//    [fAction setValue:[UIColor signColor] forKey:@"_titleTextColor"];
    [alertView addAction:fAction];
    
    UIAlertAction *cancelAction =  [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        cancelBlock();
    }];
//    [cancelAction setValue:[UIColor signColor] forKey:@"_titleTextColor"];
    [alertView addAction:cancelAction];
    //ipad设置
    if (alertView.popoverPresentationController != nil) {
        alertView.popoverPresentationController.sourceView = self.view;
        alertView.popoverPresentationController.sourceRect = CGRectMake(0, Main_Screen_Height-100, Main_Screen_Width, 100);
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:alertView animated:YES completion:nil];
    });

}

/** 带取消按钮的Sheet弹框（两个） */
- (void)showActionSheetWithSubTitle:(NSString *)subTitle secondTitle:(NSString *)secondTitle cancelTitle:(NSString *)cancelTitle confirmBlock:(ConfirmClickBlock)confirmBlock  secondBlock:(CancelClickBlock)secondBlock cancelBlock:(CancelClickBlock)cancelBlock{
    UIAlertController * alertView = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *fAction = [UIAlertAction actionWithTitle:subTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        confirmBlock();
    }];
//    [fAction setValue:[UIColor themeColor] forKey:@"titleTextColor"];
    [alertView addAction:fAction];

    UIAlertAction *sAction =[UIAlertAction actionWithTitle:secondTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        secondBlock();
    }];
//    UIImage *secondImage = [[UIImage imageNamed:@"sphy_jt"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    [sAction setValue:secondImage forKey:@"image"];
//    [sAction setValue:[UIColor themeColor] forKey:@"titleTextColor"];
    [alertView addAction:sAction];
    
    UIAlertAction *cancelAction =  [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        cancelBlock();
    }];
//    [cancelAction setValue:[UIColor signColor] forKey:@"_titleTextColor"];
    [alertView addAction:cancelAction];
    //ipad设置
    if (alertView.popoverPresentationController != nil) {
        alertView.popoverPresentationController.sourceView = self.view;
        alertView.popoverPresentationController.sourceRect = CGRectMake(0, Main_Screen_Height-160, Main_Screen_Width, 160);
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:alertView animated:YES completion:nil];
    });



}

/** 带取消按钮的Sheet弹框（三个） */
- (void)showActionSheetWithSubTitle:(NSString *)subTitle secondTitle:(NSString *)secondTitle thirdTitle:(NSString *)thirdTitle cancelTitle:(NSString *)cancelTitle confirmBlock:(ConfirmClickBlock)confirmBlock  secondBlock:(CancelClickBlock)secondBlock thirdBlock:(CancelClickBlock)thirdBlock cancelBlock:(CancelClickBlock)cancelBlock{
    UIAlertController * alertView = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *fAction = [UIAlertAction actionWithTitle:subTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        confirmBlock();
    }];
    [alertView addAction:fAction];
    
    UIAlertAction *sAction =[UIAlertAction actionWithTitle:secondTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        secondBlock();
    }];
    [alertView addAction:sAction];
    
    UIAlertAction *tAction =[UIAlertAction actionWithTitle:thirdTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        thirdBlock();
    }];
    [alertView addAction:tAction];
    
    UIAlertAction *cancelAction =  [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        cancelBlock();
    }];
    [alertView addAction:cancelAction];
    
    //ipad设置
    if (alertView.popoverPresentationController != nil) {
        alertView.popoverPresentationController.sourceView = self.view;
        alertView.popoverPresentationController.sourceRect = CGRectMake(0, Main_Screen_Height-160, Main_Screen_Width, 160);
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:alertView animated:YES completion:nil];
    });
    
}

/** 带取消按钮的Sheet弹框（四个） */
- (void)showActionSheetWithSubTitle:(NSString *)subTitle secondTitle:(NSString *)secondTitle thirdTitle:(NSString *)thirdTitle fourthTitle:(NSString *)fourthTitle cancelTitle:(NSString *)cancelTitle confirmBlock:(ConfirmClickBlock)confirmBlock  secondBlock:(CancelClickBlock)secondBlock thirdBlock:(CancelClickBlock)thirdBlock fourthBlock:(CancelClickBlock)fourthBlock cancelBlock:(CancelClickBlock)cancelBlock{
    UIAlertController * alertView = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *fAction = [UIAlertAction actionWithTitle:subTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        confirmBlock();
    }];
    [alertView addAction:fAction];
    
    UIAlertAction *sAction =[UIAlertAction actionWithTitle:secondTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        secondBlock();
    }];
    [alertView addAction:sAction];
    
    UIAlertAction *tAction =[UIAlertAction actionWithTitle:thirdTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        thirdBlock();
    }];
    [alertView addAction:tAction];
    
    UIAlertAction *fourthAction =[UIAlertAction actionWithTitle:fourthTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        fourthBlock();
    }];
    [alertView addAction:fourthAction];
    
    UIAlertAction *cancelAction =  [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        cancelBlock();
    }];
    [alertView addAction:cancelAction];
    
    //ipad设置
    if (alertView.popoverPresentationController != nil) {
        alertView.popoverPresentationController.sourceView = self.view;
        alertView.popoverPresentationController.sourceRect = CGRectMake(0, Main_Screen_Height-160, Main_Screen_Width, 160);
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:alertView animated:YES completion:nil];
    });
    
}

/** 带一个按钮的提示框 */
- (void)showAlertViewWithTitle:(NSString *)title subTitle:(NSString *)subTitle confirmBtnTitle:(NSString *)confirmTitle confirmBlock:(ConfirmClickBlock)confirmBlock
{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:subTitle preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:confirmTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        confirmBlock();
    }];
    [alertVC addAction:confirmAction];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:alertVC animated:YES completion:nil];
    });
}


/**
 *  提示框
 */
- (void)showActionSheetWithTitle:(NSString *)title subTitle:(NSString *)subTitle confirmTitle:(NSString *)confirmTitle cancelTitle:(NSString *)cancelTitle confirmBlock:(ConfirmClickBlock)confirmBlock cancelBlock:(CancelClickBlock)cancelBlock
{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:subTitle preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        cancelBlock();
    }];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:confirmTitle style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        confirmBlock();
    }];
    [alertVC addAction:confirmAction];
    [alertVC addAction:cancelAction];
    //ipad设置
    if (alertVC.popoverPresentationController != nil) {
        alertVC.popoverPresentationController.sourceView = self.view;
        alertVC.popoverPresentationController.sourceRect = CGRectMake(0, Main_Screen_Height-160, Main_Screen_Width, 160);
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:alertVC animated:YES completion:nil];
    });
}


/**
 *  提示框(有取消)
 */
- (void)showActionSheetWithTitle:(NSString *)title subTitle:(NSString *)subTitle firstTitle:(NSString *)firstTitle secondTitle:(NSString *)secondTitle firstBlock:(ConfirmClickBlock)firstBlock secondBlock:(CancelClickBlock)secondBlock
{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:subTitle preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *firstAction = [UIAlertAction actionWithTitle:firstTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        firstBlock();
    }];
    UIAlertAction *secondAction = [UIAlertAction actionWithTitle:secondTitle style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        secondBlock();
    }];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

    }];
    [alertVC addAction:firstAction];
    [alertVC addAction:secondAction];
    [alertVC addAction:cancelAction];
    //ipad设置
    if (alertVC.popoverPresentationController != nil) {
        alertVC.popoverPresentationController.sourceView = self.view;
        alertVC.popoverPresentationController.sourceRect = CGRectMake(0, Main_Screen_Height-160, Main_Screen_Width, 160);
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:alertVC animated:YES completion:nil];
    });
}


/**
 *  提示框(一个)
 */
- (void)showActionSheetWithTitle:(NSString *)title subTitle:(NSString *)subTitle confirmTitle:(NSString *)confirmTitle confirmBlock:(ConfirmClickBlock)confirmBlock
{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:subTitle preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:confirmTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        confirmBlock();
    }];
    [alertVC addAction:confirmAction];
    //ipad设置
    if (alertVC.popoverPresentationController != nil) {
        alertVC.popoverPresentationController.sourceView = self.view;
        alertVC.popoverPresentationController.sourceRect = CGRectMake(0, Main_Screen_Height-100, Main_Screen_Width, 100);
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:alertVC animated:YES completion:nil];
    });
}


- (MBProgressHUD *)HUD{
    return objc_getAssociatedObject(self, HttpRequestHUDKey);
    
}

- (MBProgressHUD *)proHud{
    
    MBProgressHUD *hud = objc_getAssociatedObject(self, kHudKey);
    if (!hud) {
        UIView *hudSuperView = self.view;
        hud = [[MBProgressHUD alloc] initWithView:hudSuperView];
        hud.removeFromSuperViewOnHide = YES;
        [hudSuperView addSubview:hud];
        self.proHud = hud;
    }
    return hud;
}

- (void)setProHud:(MBProgressHUD *)proHud{
    objc_setAssociatedObject(self, kHudKey, proHud, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)setHUD:(MBProgressHUD *)HUD{
    objc_setAssociatedObject(self, HttpRequestHUDKey, HUD, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)showHudInView:(UIView *)view hint:(NSString *)hint{
//    MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:view];
    MBProgressHUD *HUD = self.proHud;
    if ([hint isEqualToString:@"未能读取数据，因为格式不正确。"]) {
        hint = @"无法连接到服务器";
    }
    HUD.label.text = hint;
    [view addSubview:HUD];
    [HUD showAnimated:YES];
    HUD.removeFromSuperViewOnHide = YES;
    DLog(@"show2222   %@",HUD);
//    [self setHUD:HUD];
//    [HUD hide:YES afterDelay:10];
}
- (void)showHudInView3:(UIView *)view hint:(NSString *)hint{
    MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:view];
    if ([hint isEqualToString:@"未能读取数据，因为格式不正确。"]) {
        hint = @"无法连接到服务器";
    }
    HUD.label.text = hint;
    [view addSubview:HUD];
    [HUD showAnimated:YES];
    [self setHUD:HUD];
    [HUD hideAnimated:YES afterDelay:3];
}

- (void)showHudInView10:(UIView *)view hint:(NSString *)hint{
    MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:view];
    if ([hint isEqualToString:@"未能读取数据，因为格式不正确。"]) {
        hint = @"无法连接到服务器";
    }
    HUD.label.text = hint;
    [view addSubview:HUD];
    [HUD showAnimated:YES];
    [self setHUD:HUD];
    [HUD hideAnimated:YES afterDelay:10];
}

- (void)showHint:(NSString *)hint
{
    UIView *view = [[UIApplication sharedApplication].delegate window];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.userInteractionEnabled = NO;
    // Configure for text only and offset down
    hud.mode = MBProgressHUDModeText;
    if ([hint isEqualToString:@"未能读取数据，因为格式不正确。"]) {
        hint = @"无法连接到服务器";
    }
    hud.label.text = hint;
    hud.margin = 10.f;
    hud.yOffset = 180;
    hud.removeFromSuperViewOnHide = YES;
    [hud hideAnimated:YES afterDelay:2];
}

- (void)showHint:(NSString *)hint yOffset:(float)yOffset
{
    UIView *view = [[UIApplication sharedApplication].delegate window];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.userInteractionEnabled = NO;
    // Configure for text only and offset down
    hud.mode = MBProgressHUDModeText;
    if ([hint isEqualToString:@"未能读取数据，因为格式不正确。"]) {
        hint = @"无法连接到服务器";
    }
    hud.label.text = hint;
    hud.margin = 10.f;
    hud.yOffset = 180;
    hud.yOffset += yOffset;
    hud.removeFromSuperViewOnHide = YES;
    [hud hideAnimated:YES afterDelay:2];
}

- (void)hideHud{
    [self.proHud hideAnimated:YES];
    DLog(@"hiden111  %@",self.proHud);
//    NSEnumerator *subviewsEnum = [self.view.subviews reverseObjectEnumerator];
//    for (UIView *subview in subviewsEnum) {
//        if ([subview isKindOfClass:[MBProgressHUD class]]) {
////            return (MBProgressHUD *)subview;
//            [subview removeFromSuperview];
//        }
//    }
}



///// OA ////



-(void)showSuccess:(NSString *)success
{
    MBProgressHUD *HUD=[[MBProgressHUD alloc]initWithView:[self getView]];
    HUD.contentColor=[UIColor whiteColor];
    HUD.bezelView.color=[UIColor blackColor];
    HUD.mode=MBProgressHUDModeText;
    if ([success isEqualToString:@"未能读取数据，因为格式不正确。"]) {
        success = @"无法连接到服务器";
    }
    HUD.label.text=success;
    HUD.removeFromSuperViewOnHide=YES;
    [[self getView] addSubview:HUD];
    [HUD showAnimated:YES];
    [HUD hideAnimated:YES afterDelay:1];
}
-(void)showError:(NSString *)error
{
    MBProgressHUD *HUD=[[MBProgressHUD alloc]initWithView:[self getView]];
    HUD.contentColor=[UIColor whiteColor];
    HUD.bezelView.color=[UIColor blackColor];
    HUD.mode=MBProgressHUDModeText;
    if ([error isEqualToString:@"未能读取数据，因为格式不正确。"]) {
        error = @"无法连接到服务器";
    }
    HUD.label.text=error;
    HUD.removeFromSuperViewOnHide=YES;
    [[self getView] addSubview:HUD];
    [HUD showAnimated:YES];
    [HUD hideAnimated:YES afterDelay:1];
}
-(void)showMessage:(NSString *)message
{
    MBProgressHUD *HUD=[[MBProgressHUD alloc]initWithView:[self getView]];
    HUD.contentColor=[UIColor whiteColor];
    HUD.bezelView.color=[UIColor blackColor];
    HUD.mode=MBProgressHUDModeText;
    if ([message isEqualToString:@"未能读取数据，因为格式不正确。"]) {
        message = @"无法连接到服务器";
    }
    HUD.label.text=message;
    HUD.removeFromSuperViewOnHide=YES;
    [[self getView] addSubview:HUD];
    [HUD showAnimated:YES];
    [HUD hideAnimated:YES afterDelay:1];
}
-(void)showWaiting
{
    MBProgressHUD *HUD=[[MBProgressHUD alloc]initWithView:[self getView]];
    HUD.backgroundView.color = [UIColor colorWithWhite:0.f alpha:.2f];
    HUD.bezelView.color = [UIColor blackColor];
    HUD.contentColor=[UIColor whiteColor];
    HUD.removeFromSuperViewOnHide=YES;
    [[self getView] addSubview:HUD];
    [HUD showAnimated:YES];
}
-(void)showLoading
{
    MBProgressHUD *HUD=[[MBProgressHUD alloc]initWithView:[self getView]];
    HUD.backgroundView.color = [UIColor colorWithWhite:0.f alpha:.2f];
    HUD.bezelView.color = [UIColor blackColor];
    HUD.contentColor=[UIColor whiteColor];
    HUD.label.text=@"正在加载";
    HUD.removeFromSuperViewOnHide=YES;
    [[self getView] addSubview:HUD];
    [HUD showAnimated:YES];
}
-(void)showLoadingWithMessage:(NSString *)message
{
    MBProgressHUD *HUD=[[MBProgressHUD alloc]initWithView:[self getView]];
    HUD.backgroundView.color = [UIColor colorWithWhite:0.f alpha:.2f];
    HUD.bezelView.color = [UIColor blackColor];
    HUD.contentColor=[UIColor whiteColor];
    if ([message isEqualToString:@"未能读取数据，因为格式不正确。"]) {
        message = @"无法连接到服务器";
    }
    HUD.label.text=message;
    HUD.removeFromSuperViewOnHide=YES;
    [[self getView] addSubview:HUD];
    [HUD showAnimated:YES];
}
-(void)showSaving
{
    MBProgressHUD *HUD=[[MBProgressHUD alloc]initWithView:[self getView]];
    HUD.backgroundView.color = [UIColor colorWithWhite:0.f alpha:.2f];
    HUD.bezelView.color = [UIColor blackColor];
    HUD.contentColor=[UIColor whiteColor];
    HUD.label.text=@"正在保存";
    HUD.removeFromSuperViewOnHide=YES;
    [[self getView] addSubview:HUD];
    [HUD showAnimated:YES];
}
-(void)hideHUD
{
    [MBProgressHUD hideHUDForView:[self getView] animated:YES];
}
-(UIView *)getView
{
    UIView *view;
    if (self.navigationController.view) {
        view=self.navigationController.view;
    }else
    {
        view=self.view;
    }
    return view;
}


-(void)zt_showLoading
{
    MBProgressHUD *HUD=[[MBProgressHUD alloc]initWithView:self.view];
    HUD.backgroundView.color = [UIColor colorWithWhite:0.f alpha:.2f];
    HUD.bezelView.color = [UIColor blackColor];
    HUD.contentColor=[UIColor whiteColor];
    HUD.label.text=@"正在加载";
    [self.view addSubview:HUD];
    [HUD showAnimated:YES];
}

-(void)zt_hideHUD
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
@end
